package com.fyzk.activity.lottery.shuzicai;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.PopupWindow;

import com.fyzk.activity.lottery.basketball.JCLQSelectPlayMethodPop;
import com.tyjc.lottery.R;

/**
 * Created by miao on 16/10/8.
 */

public class PopFC3DSelectPlayMethod extends PopupWindow implements CompoundButton.OnCheckedChangeListener {


    private CheckBox d3_normal, d3_group3,d3_group6,cb_selectplaymethod_group7;

    public PopFC3DSelectPlayMethod(Context context, int width, int height) {
        super(width, height);
        View view = View.inflate(context, R.layout.layout_selectplaymethod_3d, null);
        this.setContentView(view);
        initView(view);
        this.setOutsideTouchable(true);
        this.setBackgroundDrawable(context.getResources().getDrawable(R.color.transparent));
        // 设置此参数获得焦点，否则无法点击
        this.setFocusable(true);
        // TODO Auto-generated constructor stub
    }
    public PopFC3DSelectPlayMethod(Context context, int width, int height,boolean isPl3) {
        super(width, height);
        View view = View.inflate(context, R.layout.layout_selectplaymethod_3d, null);
        this.setContentView(view);
        initView(view);
        if(isPl3){
            cb_selectplaymethod_group7.setVisibility(View.VISIBLE);
        }else {
            cb_selectplaymethod_group7.setVisibility(View.GONE);
        }
        this.setOutsideTouchable(true);
        this.setBackgroundDrawable(context.getResources().getDrawable(R.color.transparent));
        // 设置此参数获得焦点，否则无法点击
        this.setFocusable(true);
        // TODO Auto-generated constructor stub
    }

    private void initView(View view) {
        // TODO Auto-generated method stub
        d3_normal = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_normal);
        d3_group3 = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_group3);
        d3_group6 = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_group6);
        cb_selectplaymethod_group7 = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_group7);
        d3_normal.setOnCheckedChangeListener(this);
        d3_group3.setOnCheckedChangeListener(this);
        d3_group6.setOnCheckedChangeListener(this);
        cb_selectplaymethod_group7.setOnCheckedChangeListener(this);

    }

    private void clearChecked(){
        d3_normal.setOnCheckedChangeListener(null);
        d3_group3.setOnCheckedChangeListener(null);
        d3_group6.setOnCheckedChangeListener(null);
        cb_selectplaymethod_group7.setOnCheckedChangeListener(null);
        d3_normal.setChecked(false);
        d3_group3.setChecked(false);
        d3_group6.setChecked(false);
        cb_selectplaymethod_group7.setChecked(false);
        d3_normal.setOnCheckedChangeListener(this);
        d3_group3.setOnCheckedChangeListener(this);
        d3_group6.setOnCheckedChangeListener(this);
        cb_selectplaymethod_group7.setOnCheckedChangeListener(this);

    }



    public void setOnWFCheckChangedListener(JCLQSelectPlayMethodPop.OnWFCheckChangedListener listener ){
        this.listener = listener;
    }


    private JCLQSelectPlayMethodPop.OnWFCheckChangedListener listener = null;

    public interface OnWFCheckChangedListener{
        void onWFCheckChange(int id, boolean isChecked);
    }

    @Override
    public void showAtLocation(View parent, int gravity, int x, int y) {
        super.showAsDropDown(parent);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // TODO Auto-generated method stub
        clearChecked();
        buttonView.setOnCheckedChangeListener(null);
        buttonView.setChecked(isChecked);
        buttonView.setOnCheckedChangeListener(this);
        if(listener!=null){
            listener.onWFCheckChange(buttonView.getId(),isChecked);
        }
        //已选中的玩法CheckBox 不能再点击
        d3_normal.setEnabled(!d3_normal.isChecked());
        d3_group3.setEnabled(!d3_group3.isChecked());
        d3_group6.setEnabled(!d3_group6.isChecked());
        cb_selectplaymethod_group7.setEnabled(!cb_selectplaymethod_group7.isChecked());
    }

}
